from django import forms
from . import models
import hashlib
class UserForm(forms.Form):
    username=forms.CharField(max_length=10,min_length=5)
    password=forms.CharField(max_length=15,min_length=6)
    # forms.IntegerField
    # forms.FloatField
    # forms.ImageField
    # forms.FileField
    # forms.EmailField
    # forms.BooleanField
    # forms.DateTimeField
    # forms.DateField

    def clean_username(self):
        username=self.data.get("username")
        if models.User.objects.filter(username=username).exists():
            self.add_error("username","用户已存在")
        else:
            return username

    def clean_password(self):
        password=self.data.get("password")
        m=hashlib.md5(password.encode())
        new_password=m.hexdigest()
        return new_password